<?php

function stumbleinfo_request($name, $default=null)
{
	if (!isset($_REQUEST[$name])) return $default;
	if (get_magic_quotes_gpc()) return stumbleinfo_stripslashes($_REQUEST[$name]);
	else return $_REQUEST[$name];
}

function stumbleinfo_stripslashes($value)
{
	$value = is_array($value) ? array_map('stumbleinfo_stripslashes', $value) : stripslashes($value);
	return $value;
}

function stumbleinfo_field_text($name, $label='', $tips='', $attrs='')
{
  global $options;
  if (strpos($attrs, 'size') === false) $attrs .= 'size="30"';
  echo '<tr><td class="label">';
  echo '<label for="options[' . $name . ']">' . $label . '</label></td>';
  echo '<td><input type="text" ' . $attrs . ' name="options[' . $name . ']" value="' .
    htmlspecialchars($options[$name]) . '"/>';
  echo ' ' . $tips;
  echo '</td></tr>';
}


function stumbleinfo_field_checkbox($name, $label='', $tips='', $attrs='')
{
  global $options;
  echo '<tr><td class="label">';
  echo '<label for="options[' . $name . ']">' . $label . '</label></td>';
  echo '<td><input type="checkbox" ' . $attrs . ' name="options[' . $name . ']" value="1" ' .
    ($options[$name]!= null?'checked':'') . '/>';
  echo ' ' . $tips;
  echo '</td></tr>';
}

function stumbleinfo_field_radio($name, $label='', $tips='', $attrs='', $value='')
{
  global $options;
  echo '<tr><td class="label">';
  echo '<label for="options[' . $name . ']">' . $label . '</label></td>';
  echo '<td><input type="radio" ' . $attrs . ' name="options[' . $name . ']" value="' . $value . '" ' .
    ($options[$name]== $value?'checked':'') . '/>';
  echo ' ' . $tips;
  echo '</td></tr>';
}

if (isset($_POST['Submit']))
{
  $options = stumbleinfo_request('options');
  update_option('stumbleinfo', $options);
}
else
{
    $options = get_option('stumbleinfo');
}

?>

<div class="wrap">
<form method="post">

<h2>Stumbleinfo Icon</h2>

<ol>
	<li> shows a su popularity indicator next to every link on your weblog.
	<li> gives you a function to show if your own weblogpostings have been
		  stumbled, and if so, how popular they are.
</ol>
<hr />
<h3> 1. Icon or Text </h3>
<p>
	Do you want to display the indicator as an icon or as plain text?<br />
</p>
<table>
	<? stumbleinfo_field_radio('stumbleinfo_showicon', 'Show Icon', '', '', '1');  ?>
	<? stumbleinfo_field_radio('stumbleinfo_showicon', 'Show Text', '', '', '2');  ?>
</table>
<hr />
<h3> Icon options </h3>
<p>
	If you choose the icon option above, which iconset do you need?<br />
</p>
<table>
	<? stumbleinfo_field_radio('stumbleinfo_button', 'Buttons for white background', '', '', '1') ?>
   <? stumbleinfo_field_radio('stumbleinfo_button', 'Buttons for black background', '', '', '2') ?>
</table>
<hr />
<h3> Text options </h3>
<p>
	If you choose the text option above, which lines of text do you want?<br />
</p>
<table>
	<? stumbleinfo_field_text('stumbleinfo_beforesu', 'Text before the indicator', 'e.g. "  ("'); ?>
	<? stumbleinfo_field_text('stumbleinfo_aftersu', 'Text after the indicator', 'e.g. " reviews)"'); ?>
	<? stumbleinfo_field_text('stumbleinfo_loser', 'Text for sites not in su yet', 'e.g. "please stumble this!"'); ?>
	<? stumbleinfo_field_text('stumbleinfo_winner', 'Text for super sites', 'e.g. "supersite!"'); ?>
</table>
<hr />
<h3> Bookmark button only </h3>
<p>
If you only want to use the bookmark button but not the site wide replacement
then tick the following. It will still use the settings you defined above.
</p>
<table>
	<? stumbleinfo_field_checkbox('stumbleinfo_onlybutton', 'Only the button!', '');  ?>
</table>
<hr>
<p>
The code you can use in your template for the single bookmark button/text:
</p>
<code>
	stumbleInfoButton(get_permalink(),get_the_title(),'submit');
</code>
<p>
(Read <a href="http://weblogtoolscollection.com/archives/2008/08/20/safest-way-to-include-plugin-code-in-themes/">here</a>
on how to do that safely).<br />
I assume that you always want the link to be a "submit to SU" link for "the single button".
However if you only want to view the reviews just replace 'submit' with 'view'.
</p>
<hr />
<h3> Your own stylesheet </h3>
<p>
If you want your own stylesheet to format buttons/text and/or use your own buttons, then
just choose to use your own stylesheet. *warning* : if you tick this one and do not have
your own styling in place, the links will look like a mess!
</p>
<table>
	<? stumbleinfo_field_checkbox('stumbleinfo_ownstylesheet', 'Use my own stylesheet!', '');  ?>
</table>

<p>
	<a href="http://edward.de.leau.net/stumble-info-icon-plugin" target="_blank">Main homepage of the plugin</a>.<br />
	<a href="http://code.google.com/p/wp-su-plugin/issues/list" target="_blank">Report issues here</a>.<br />
	<a href="http://edward.de.leau.net">weblog of author: Edward de Leau</a><br />
</p>

<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
</p>

</form>
</div>

